﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace calculater
{
    public partial class Form1 : Form
    {

        double number=0, number2 = 0, result;

        int inputnumber;

        enum operationeration { clean,plus ,subtract, multply ,divide}
        operation mode = operation.clean;
        bool isequal = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void labelout_Click(object sender, EventArgs e)
        {

        }

        public void jishu (int a)
        {
            if (mode==operation.clean)
            {
                number = number * 10 + a;
                labelout.Text = Convert.ToString(number);
            }
            else
            {
                number2 = number2 * 10 + a;
                labelout.Text = Convert.ToString(number2);
            }
        }

        private void num1_Click(object sender, EventArgs e)
        {
            inputnumber = 1;
            jishu(inputnumber);
        }

        private void num2_Click(object sender, EventArgs e)
        {
            inputnumber = 2;
            jishu(inputnumber);
        }

        private void num3_Click(object sender, EventArgs e)
        {
            inputnumber = 3;
            jishu(inputnumber);
        }

        private void num4_Click(object sender, EventArgs e)
        {
            inputnumber = 4;
            jishu(inputnumber);
        }

        private void num5_Click(object sender, EventArgs e)
        {
            inputnumber = 5;
            jishu(inputnumber);
        }

        private void num6_Click(object sender, EventArgs e)
        {
            inputnumber = 6;
            jishu(inputnumber);
        }

        private void num7_Click(object sender, EventArgs e)
        {
            inputnumber = 7;
            jishu(inputnumber);
        }

        private void num8_Click(object sender, EventArgs e)
        {
            inputnumber = 8;
            jishu(inputnumber);
        }

        private void num9_Click(object sender, EventArgs e)
        {
            inputnumber = 9;
            jishu(inputnumber);
        }

        private void num0_Click(object sender, EventArgs e)
        {
            inputnumber = 0;
            jishu(inputnumber);
        }

        private void plus_Click(object sender, EventArgs e)
        {
            mode = operation.plus;
            switchmode();
         
        }

        private void clear_Click(object sender, EventArgs e)
        {
            clean();
          
        }

        private void subtract_Click(object sender, EventArgs e)
        {
            mode = operation.subtract;
            switchmode();
        }

        private void multply_Click(object sender, EventArgs e)
        {
            mode = operation.multply;
            switchmode();
        }

        private void divide_Click(object sender, EventArgs e)
        {
            mode = operation.divide;
            switchmode();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void equal_Click(object sender, EventArgs e)
        {
            switch (mode)
            {
                case operation.plus:
                    result = number + number2;
                    break;
                case operation.subtract:
                    result = number - number2;
                    break;
                case operation.multply:
                    result = number * number2;
                    break;
                case operation.divide:
                    result = number / number2;
                    break;
            }
            number = 0;
            number2 = 0;
           labelout.Text = Convert.ToString(result);
            isequal = true;
            label1.Text = "";
            labelmode.Text = "";
        //    labelout.Text = Convert.ToString(result);

        }

        private void labelmode_Click(object sender, EventArgs e)
        {

        }

        public void clean()
        {

            number = 0;
            number2 = 0;
            labelout.Text = Convert.ToString(number);
            label1.Text = "";
            labelmode.Text = "";
            
     isequal = false;
            mode = operation.clean;
        }
        public void switchmode()
        {
            switch (mode)
            {
                case operation.plus:
                    labelmode.Text = "+";
                    break;
                case operation.subtract:
                    labelmode.Text = "-";
                    break;
                case operation.multply:
                    labelmode.Text = "*";
                    break;
                case operation.divide:
                    labelmode.Text = "/";
                    break;
            }
            if (isequal == true)
            {
                number = result;
            }
            label1.Text = Convert.ToString(number);
            labelout.Text = Convert.ToString(number2);
        }
        }
    }

